<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%-- <%@include file="../../../common/taglib/taglib.jsp"%> --%>
<script language="javaScript">
function selectAll(){
	$("[name=items]:checkbox").attr("checked",$("#all").prop("checked"));
}
function searchData(isUser){
	var userNo = $("#userNo").val();
	if(isUser == '1'){
		$("#agentInfo").attr("action","${baseURL }/agent/agentBind?isUser=1&userNo="+userNo);
	}else{
		var userNo = $("#userNo").val();
		if(userNo != ''){
			$("#agentInfo").attr("action","${baseURL }/agent/agentBind?isUser=0&userNo="+userNo);
		}else{
			alertMsg.error("请选择需过滤数据的用户！");
			return;
		}
	}
	$("#agentInfo").submit();
}
function btnSecond(){
	var userNo = $("#userNo").val();
	 var agentIds = "";
     $('input:checkbox[name=items]:checked').each(function(i){
      if(0==i){
    	  agentIds = $(this).val();
      }else{
    	  agentIds += (","+$(this).val());
      }
     });
	if(userNo != ''&& agentIds!=''){
		$.ajax({  
            type: "POST",
            dataType : "json",
            data:{userNo : userNo,
            	agentIds : agentIds
            },
            url: "${baseURL }/agent/addAgentBind",
            //请求成功完成后要执行的方法  
            success: function(obj){
            	if(obj.code == '0'){
            		
            		alertMsg.correct('操作成功！')
            	}else{
            		alertMsg.error(obj.msg);
            	}
            },  
            error : function() {
            	alertMsg.error("系统异常！");
            }   
        });
	}else{
		alertMsg.warn("请选择用户和代理商！");
	}
}
</script>
<form id="pagerForm" method="post" action="${baseURL }/agent/agentBind">
	<%@include file="../common/pageParameter.jsp"%>
</form>
<div class="pageHeader">
	<form rel="pagerForm" onsubmit="return navTabSearch(this);" action="${baseURL }/agent/agentBind" method="post" id="agentInfo">
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td>
						代理编号：
						<input type="text" name="agentNo" />
					</td>
					<td>
						<div class="buttonActive">
							<div class="buttonContent">
								<button title="查询" type="btnSearch" onclick="searchData(1)">查&nbsp;询</button>
							</div>
						</div>
					</td>
				</tr>
				<tr>
				</tr>
			</table>
		</div>
	</form>
</div>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<%-- <li>
				<shiro:hasPermission name="user:secondMerchant:add">
					<a title="添加通道二级商户" class="add" href="${baseURL }/user/info/addSecondMerchantUI" target="navTab">
						<span>添加通道二级商户</span>
					</a>
				</shiro:hasPermission>
			</li> --%>
			<li class="line">line</li>
		</ul>
	</div>
	<div class="panelBar">
		<ul class="toolBar">
			<li>
				<shiro:hasPermission name="user:secondMerchant:add">
					用户：<select name="userNo" id="userNo">
									<option value="">请选择</option>
								<c:forEach var="item" items="${agentList}">
									<option value="${item.userNo }" <c:if test="${item.userNo == userNo}"> selected="selected"</c:if>>${item.userName }【${item.userNo }】</option>
								</c:forEach>
							</select>
					<button title="绑定代理" type="button" id="btnSecond" onclick="btnSecond()">绑定代理</button>
				</shiro:hasPermission>
			</li>
			<li class="line">line</li>
			<li>
				<shiro:hasPermission name="user:secondMerchant:add">
					<button title="过滤该代理已绑定的代理商" type="button" id="btnFlush" onclick="searchData(0)">过滤该代理已绑定的代理商</button>
				</shiro:hasPermission>
			</li>
			<li class="line">line</li>
		</ul>
	</div>
	
	<table class="table" width="100%" layoutH="137">
		<thead>
			<tr>
				<th width="36"><input type="checkbox" name="all" id="all" onclick="selectAll()"/> </th>
				<th width="130">创建时间</th>
				<th width="180">用户编号</th>
				<th width="100">登录账号</th>
				<th width="200">用户名称</th>
				<th width="80">用户类型</th>
				<th width="50">状态</th>
				<!-- <th>操作</th> -->
			</tr>
		</thead>
		<tbody>
			<c:forEach var="item" items="${pageBean.recordList}" varStatus="s">
				<tr>
					<td><input type="checkbox" class="items" name="items" value="${item.id}" /></td>
					<td>
						<fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss" />
					</td>
					<td>${item.userNo}</td>
					<td>${item.mobile}</td>
					<td>${item.userName}</td>
					<td>${item.userTypeDesc}</td>
					<td>
						<c:if test="${item.status=='ACTIVE'}">
							<font color="blue">${item.statusDesc}</font>
						</c:if>
						<c:if test="${item.status=='UNACTIVE'}">
							<font color="red">${item.statusDesc}</font>
						</c:if>
						<c:if test="${item.status!='ACTIVE' && item.status!='UNACTIVE'}">
							<font color="gray">${item.statusDesc}</font>
						</c:if>
					</td>
					<%-- <td>
						<shiro:hasPermission name="user:secondMerchant:add">
							<c:if test="${item.status!='ACTIVE'}">
								[&nbsp;<a title="确定要激活吗？" target="ajaxTodo" href="${baseURL }/user/info/editSecondMerchantStatus?id=${item.id}&status=100" style="color: red;">激活</a>&nbsp;]
							</c:if>
							<c:if test="${item.status=='ACTIVE'}">
								[&nbsp;<a title="确定要冻结吗？" target="ajaxTodo" href="${baseURL }/user/info/editSecondMerchantStatus?id=${item.id}&status=101" style="color: blue;">冻结</a>&nbsp;]
							</c:if>
						</shiro:hasPermission>
					</td> --%>
				</tr>
			</c:forEach>
			<c:if test="${pageBean.totalCount==0}">
				<tr>
					<td>暂无数据</td>
				</tr>
			</c:if>
		</tbody>
	</table>
	<%@include file="../common/pageBar.jsp"%>
</div>